package com.dididoctor.patient.Activity.Usercentre;

import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dididoctor.patient.Activity.Usercentre.Collect.UserCollectActivity;
import com.dididoctor.patient.Activity.Usercentre.Combo.ComboActivity;
import com.dididoctor.patient.Activity.Usercentre.Consume.UserConsumeActivity;
import com.dididoctor.patient.Activity.Usercentre.Evaluate.UserEvaluateActivity;
import com.dididoctor.patient.Activity.Usercentre.Record.RecordActivity;
import com.dididoctor.patient.Activity.Usercentre.Setting.UserSettingActivity;
import com.dididoctor.patient.Activity.Usercentre.Userinfo.UserInfoActivity;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.UserHeadImage;
import com.dididoctor.patient.Utils.Util;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： UserCentreActivity
 * @包名称：
 * @创建人： zhanjunjie
 * @创建时间：2016/4/1 15:51
 * @修改人：
 * @修改时间：2016/4/1 15:51
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class UserCentreActivity extends EduActivity {


    private TextView mTvUserName, mTvUserPhone;
    private UserHeadImage headImage;
    private ImageView mIvGender;
    private LoaderImage loaderImage;


    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_user_centre);
    }

    @Override
    public void init() {
        initview();


    }

    private void initdata() {
        mTvUserName.setText(Token.getName());
        mTvUserPhone.setText(Token.getPhone());
        String gender = Token.getSex();//0 女 1 男
        if (!Util.isEmpty(gender)) {
            if (gender.equals("0")) {
                mIvGender.setImageResource(R.drawable.icon_girl);
            } else {
                mIvGender.setImageResource(R.drawable.icon_boy);
            }
        }

        loaderImage.load(headImage, Token.getHeadPic(), new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                headImage.setImageResource(R.drawable.img_userdefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                headImage.setImageResource(R.drawable.img_userdefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        initdata();
//        mTvUserName.setText(Token.getName());
    }

    private void initview() {
        mTvUserName = (TextView) findViewById(R.id.tv_username);
        mTvUserPhone = (TextView) findViewById(R.id.tv_userphone);
        headImage = (UserHeadImage) findViewById(R.id.iv_head);
        mIvGender = (ImageView) findViewById(R.id.iv_gender);
        loaderImage = new LoaderImage(this);

        findViewById(R.id.lin_user_info).setOnClickListener(this);
        findViewById(R.id.lin_combo).setOnClickListener(this);
        findViewById(R.id.lin_consume).setOnClickListener(this);
        findViewById(R.id.lin_record).setOnClickListener(this);
        findViewById(R.id.lin_evaluate).setOnClickListener(this);
        findViewById(R.id.lin_collect).setOnClickListener(this);
        findViewById(R.id.lin_setting).setOnClickListener(this);

    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            //个人信息
            case R.id.lin_user_info: {
                Intent intent = new Intent(this, UserInfoActivity.class);
                startActivity(intent);
            }
            break;
            //我的套餐
            case R.id.lin_combo: {
                Intent intent = new Intent(this, ComboActivity.class);
                startActivity(intent);
            }
            break;
            //消费记录
            case R.id.lin_consume: {
                Intent intent = new Intent(this, UserConsumeActivity.class);
                startActivity(intent);
            }
            break;
            //健康档案
            case R.id.lin_record: {
                Intent intent = new Intent(this, RecordActivity.class);
                startActivity(intent);
            }
            break;
            //我的评价
            case R.id.lin_evaluate: {
                Intent intent = new Intent(this, UserEvaluateActivity.class);
                startActivity(intent);
            }
            break;
            //我的收藏
            case R.id.lin_collect: {
                Intent intent = new Intent(this, UserCollectActivity.class);
                startActivity(intent);
            }
            break;
            //设置与帮助
            case R.id.lin_setting: {
                Intent intent = new Intent(this, UserSettingActivity.class);
                startActivity(intent);
            }
            break;
        }
    }
}
